import React, { useState } from "react";
import axios from 'axios'
import logo from '../../logo.svg'
import { useNavigate } from "react-router-dom";
import { Notify } from "react-vant";
const Index: React.FC = () => {
  const [title, setTitle] = useState("");
  const [desc, setDesc] = useState("");
	const navigate = useNavigate()
	const handleSubmit = () => {
		axios.post('/api/list/add', { title, desc, url: logo }).then(() => {
			navigate('/')
		}).catch(e => {
			Notify.show({ type: 'danger', message: e.message })
		})
	}
  return (
    <div>
      <input
        type="text"
        value={title}
        onChange={(e) => setTitle(e.target.value)}
      />
      <textarea
        name=""
        id=""
        value={desc}
        onChange={(e) => setDesc(e.target.value)}
      ></textarea>
			<button onClick={handleSubmit}>提交</button>
    </div>
  );
};

export default Index;
